﻿#region 命名空间

using System;
using System.Collections.Generic;
using Ext.Net;
using Ext.Net.MVC;
using Sharp.Infrastructure;
using Sharp.Platform;
using Sharp.Platform.List;
using Sharp.Platform.Other;
using Alignment = Ext.Net.Alignment;
using Column = Ext.Net.MVC.ColumnAttribute;
using DateColumn = Ext.Net.MVC.DateColumnAttribute;
#endregion

namespace Sharp.Web.Models
{
    [Platform.Title("用户管理")]
    [DataHandler(ModuleOP.Details, "浏览", 0)]
    [DataHandler(ModuleOP.Create, "新增", 1)]
    [DataHandler(ModuleOP.Edit, "修改", 2)]
    [DataHandler(ModuleOP.Delete, "删除", 3)]
    [DataHandler("Permission", "权限", 4)]
    public partial class UserIndexModel : IViewModel
    {
        [Column(Text = "Id", Hidden = true)]
        public Guid Id { get; set; }


        [Column(Text = "用户名", Locked = true, Width = 200)]
        public string UserName { get; set; }

        [Column(Text = "电子邮件", Width = 200)]
        public string Email { get; set; }


        [DateColumn(Text = "注册日期", Width = 130, Format = "yyyy-MM-dd", Align = Alignment.Right)]
        public DateTime? DateRegistered { get; set; }

        [Column(Text = "最后登录IP", Width = 200)]
        public string LastLoginIP { get; set; }

        [DateColumn(Text = "最后登录日期", Width = 140, Format = "yyyy-MM-dd HH:mm:ss", Align = Alignment.Right)]
        public DateTime? DateLastLogon { get; set; }

        /// <summary>
        ///     是否被锁定
        /// </summary>
        [BooleanColumn(Text = "是否被锁定", TrueText = "锁定", FalseText = "正常", Align = Alignment.Center)]
        public bool IsLockedOut { get; set; }

    }

    public partial class UserIndexModel : SharpList
    {
        public UserIndexModel()
        {
            this.Feature = ListFeature.MultiSelect | ListFeature.Paging | ListFeature.RowNumber;

            this.ToolbarButtonParameters.Add(new ToolButtonInfo()
            {
                Model = "Permission",
                Direct = new ToolButtonInfo.DirectClickAction("ListForUser", "Permission"),
                Parameters = new List<ToolButtonInfo.Parameter>()
                {
                    new ToolButtonInfo.Parameter("owner", "user", (int) ParameterMode.Auto),
                    new ToolButtonInfo.Parameter("userName",
                        "this.up('grid').getSelectionModel().getSelection()[0].getData().UserName", (int) ParameterMode.Raw),
                    new ToolButtonInfo.Parameter("ownerId",
                        "this.up('grid').getSelectionModel().getSelection()[0].getData().Id", (int) ParameterMode.Raw)
                }
            });
        }
    }
}